//
//  MineHeaderInfoView.m
//  YJlandlord
//
//  Created by 文彬 on 2018/6/26.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "MineHeaderInfoView.h"
@interface MineHeaderInfoView()

@property (strong, nonatomic) UIImageView *bgImgView;
@property (strong, nonatomic) UIImageView *headerImgView;
@property (strong, nonatomic) UILabel *nameLabel;
@property (strong, nonatomic) UIButton *settingBtn;
@property (strong, nonatomic) UIButton *pubBtn;

@end

@implementation MineHeaderInfoView

- (id)init{
    self = [super init];
    if (self) {
        
        [self addSubview:self.bgImgView];
        [self addSubview:self.settingBtn];
        [self addSubview:self.pubBtn];
        [self addSubview:self.nameLabel];
        [self addSubview:self.headerImgView];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)layoutSubviews{
    
    [self.settingBtn makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@25);
        make.height.equalTo(@25);
        make.top.equalTo(@40);
        make.right.equalTo(@-10);
    }];
    
    [self.pubBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.width.equalTo(@80);
        make.height.equalTo(@30);
        make.centerY.equalTo(self.settingBtn.centerY);
    }];
    
    [self.bgImgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    
    [self.headerImgView makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@70);
        make.height.equalTo(@70);
        make.centerX.equalTo(self.centerX);
        make.bottom.equalTo(@-80);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.right.equalTo(@-10);
        make.height.equalTo(@35);
        make.top.equalTo(self.headerImgView.bottom).offset(10);
    }];
    
    
}

#pragma mark getter
- (UIImageView*)bgImgView{
    if (_bgImgView==nil) {
        _bgImgView = [[UIImageView alloc]init];
        _bgImgView.image = [UIImage imageNamed:@"headerbg"];
    }
    
    return _bgImgView;
}

- (UIImageView*)headerImgView{
    if (_headerImgView==nil) {
        _headerImgView = [[UIImageView alloc]init];
        _headerImgView.layer.cornerRadius = 35;
        _headerImgView.clipsToBounds = YES;
        [_headerImgView sd_setImageWithURL:[NSURL URLWithString:@"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4036889747,3526425271&fm=27&gp=0.jpg"] placeholderImage:nil];
    }
    
    return _headerImgView;
}

- (UILabel*)nameLabel{
    if (_nameLabel==nil) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.font = [UIFont systemFontOfSize:18];
        _nameLabel.text = @"登录/注册";
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    
    return _nameLabel;
}

- (UIButton*)settingBtn{
    if (_settingBtn==nil) {
        _settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_settingBtn setBackgroundImage:[UIImage imageNamed:@"user_setting"] forState:UIControlStateNormal];
        [_settingBtn buttonClick:^{
        
            if ([self.delegate respondsToSelector:@selector(settingClicked)]) {
                [self.delegate settingClicked];
            }
        }];
        
    }
    
    return _settingBtn;
}

- (UIButton*)pubBtn{
    if (_pubBtn==nil) {
        _pubBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_pubBtn setTitle:@"发表故事" forState:UIControlStateNormal];
        [_pubBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _pubBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    }
    return _pubBtn;
}


@end
